﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DAL.Entities;
using System.Data.SqlClient;

namespace DAL.EntitiesDAL
{
    public class DuockhenthuongDAL : BaseDAL, UTL.IBaseDAL
    {
        #region Implement

        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            return ExecuteQuery("sp_SelectAll_Duockhenthuong");
        }

        public DataTable Select_Nhanvien()
        {
            return ExecuteQuery("sp_SelectAll_Nhanvien");
        }

        public DataTable Select_Khenthuong()
        {
            return ExecuteQuery("sp_SelectAll_Khenthuong");
        }

        public DataTable Select_Danhsach_Khenthuong(string name)
        {
            var sql = "set dateformat dmy; execute sp_SelectAll_Danhsach_Khenthuong " + name + " ";
            sql = string.Format(sql, name);
            return ExecuteQuery(sql);
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(string id)
        {
            var sql = "sp_Delete_Duockhenthuong '{0}' ";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Delete_Duockhenthuong(string id, string id1)
        {
            var sql = "sp_Delete_Duockhenthuong '{0}', '{1}' ";
            sql = string.Format(sql, id, id1);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (Duockhenthuong)obj;
            var sql = "set dateformat dmy; execute sp_Insert_Duockhenthuong '{0}', '{1}' ";
            sql = string.Format(sql, o.STT_QDKT, o.MANHANVIEN);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (Duockhenthuong)obj;
            var sql = "set dateformat dmy; execute sp_Update_Duockhenthuong '{0}', '{1}' ";
            sql = string.Format(sql, o.STT_QDKT, o.MANHANVIEN);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public DataTable Search(string name)
        {
            var sql = @"Select * from tb_Duockhenthuong";
            sql = string.Format(sql, name);
            return ExecuteQuery(sql);
        }

        public DataTable Search(DAL.Entities.Duockhenthuong o)
        {
            string sql;
            if (o.STT_QDKT != "")
                sql = @"Select * from tb_Duockhenthuong Where STT_QDKT like '%" + o.STT_QDKT + "%' ";
            else
                sql = @"Select * from tb_Duockhenthuong Where MANHANVIEN like N'%" + o.MANHANVIEN + "%' ";
           
            return ExecuteQuery(sql);
        }

        #endregion
    }
}
